<%-- 
    Document   : order_detail
    Created on : 21-Jul-2013, 08:39:55
    Author     : MrMAD
--%>

<%@page import="mybean.Cart"%>
<%@page import="mybean.BookInCart"%>
<%@page import="mybean.Book"%>
<%@page import="mybean.DBProcess"%>
<%@page import="java.util.StringTokenizer"%>
<%@page import="mybean.Customer"%>
<%@page import="mybean.Order"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>BookStore Manager</title>       
        <link rel="stylesheet" href="../MyCss/admin.css">
        <link rel="stylesheet" href="../MyCss/cart.css">
        <style>
            fieldset{
                border: 1px dashed #e6e154; 
                color: #ccff00; 
                font-size: 15px; 
                padding-bottom: 20px;
            }
            legend{                
                font-size: 17px; 
                padding-bottom: 10px;
            }
            td{
                padding: 10px;
            }
        </style>
    </head>
    <body>     
        <script src="../js/admin.js"></script>

        <h1>Order Manager</h1>
        <div><a href="logout.jsp" style="font-size: 15px;">Log out</a></div>
        <hr/>
        <%
            String id = request.getParameter("id");            

            Order order = new Order();
            order.getOrder(id);            

            Customer customer = new Customer();            
            customer.getInfoByEmail(order.getEmail());            

        %>
        <fieldset>
            <legend>Customer Information</legend>                
            <table>
                <tr>
                    <td>User name</td>
                    <td><%= customer.getName()%></td>                            
                </tr>
                <tr>
                    <td>Email</td>
                    <td><%= customer.getEmail()%></td>                            
                </tr>
                <tr>
                    <td>Phone</td>
                    <td><%= customer.getPhone()%></td>                            
                </tr>
                <tr>
                    <td>Address</td>
                    <td><%= customer.getAddress()%></td>                            
                </tr>
                <tr>
                    <td>Company</td>
                    <td><%= customer.getCompany()%></td>                            
                </tr>                        
                <tr>
                    <td>Date of birth</td>
                    <td><%= customer.getDoB()%></td>                            
                </tr>
            </table>                
        </fieldset>

        <table class="cart_table">
            <tbody>
                <tr class="cart_title">
                    <th>Cover</th>
                    <th>Name</th>
                    <th>Price</th>
                    <th>Quantity</th>
                    <th>Total</th>                            
                </tr> 
                <%
                    Cart cart = new Cart();

                    String booklist = order.getBooks();
                    StringTokenizer tokens = new StringTokenizer(booklist, "  ");
                    while (tokens.hasMoreTokens()) {
                        String bookDetail = tokens.nextToken();
                        StringTokenizer content = new StringTokenizer(bookDetail, "=");
                        while (content.hasMoreElements()) {
                            String bookID = content.nextToken();
                            DBProcess dbProcess = new DBProcess();
                            Book book = dbProcess.getBook(bookID);

                            String bookQuantity = content.nextToken();
                            BookInCart bookInCart = new BookInCart(book, Integer.parseInt(bookQuantity));                            
                            cart.add(bookInCart);
                %>
                <tr>
                    <td class="bookCover">                        
                        <img class="cart_thumb" border="0" title="" alt="cover" src="<%= book.getCover()%>">                        
                    </td>
                    <td class="bookInfo"><%= book.getBookTitle()%></td>
                    <td class="bookInfo"><%= book.getPrice()%></td>
                    <td class="bookInfo"><%= bookQuantity%></td>
                    <td class="bookInfo"><%= bookInCart.getTotalCash()%></td>
                </tr>
                <%
                        }
                    }
                %>
                <tr class="total">                                                      
                    <td class="cart_total" colspan="3">
                        <span class="red">Total</span>
                    </td>
                    <td><%= cart.getTotalQuantity()%></td>                
                    <td><%= cart.getTotalCash()%></td>
                </tr>
            </tbody>
        </table>
    </body>
</html>
